package com.zx.idc.backend.gui.mo;


import com.baomidou.mybatisplus.plugins.Page;
import com.zx.idc.backend.gui.common.BaseApi;
import com.zx.idc.backend.gui.common.Result;
import com.zx.idc.backend.gui.common.base.BaseExcelApi;
import com.zx.idc.backend.gui.common.util.NetworkUtil;
import com.zx.idc.backend.gui.shiro.TokenManagerUtil;
import com.zx.idc.common.lang.tuple.Tuple3;
import com.zx.idc.ds.mo.service.IMoFilingSuperviseService;
import com.zx.idc.ds.mo.vo.MoFilingSuperviseVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 备案监管 前端控制器
 * </p>
 *
 * @author rxliuli
 * @since 2019-03-08
 */
@RestController
@RequestMapping("/api/moFilingSupervise")
public class MoFilingSuperviseController extends BaseApi implements BaseExcelApi<IMoFilingSuperviseService, MoFilingSuperviseVo> {
    @Autowired
    private IMoFilingSuperviseService service;
    @Autowired
    private TokenManagerUtil tokenManagerUtil;

    @GetMapping("query-page")
    @RequiresPermissions("illegal-monitoring:mo-filing-supervise")
    public Result<Page<MoFilingSuperviseVo>> queryPage(Page<MoFilingSuperviseVo> page, MoFilingSuperviseVo moFilingSupervise) {
        return success(service.pageByParam(page, moFilingSupervise));
    }

    @PostMapping("/delete/batch")
    @RequiresPermissions("illegal-monitoring:mo-filing-supervise:edit")
    public Result<Boolean> deleteBatch(@RequestBody List<Long> idList) {
        return success(service.deleteBatchIds(idList));
    }

    /**
     * 批量处置监测设备
     *
     * @param tuple3 批量处置信息，分别是处置状态、说明信息以及需要处置的监测设备 id 列表
     * @return 处置结果
     */
    @PostMapping("/handle-batch")
    @RequiresPermissions("illegal-monitoring:mo-filing-supervise:edit")
    public Result<Boolean> dealBatch(@RequestBody Tuple3<Integer, String, List<MoFilingSuperviseVo>> tuple3, HttpServletRequest request) {
        return success(service.updateDealBatch(tokenManagerUtil.getCurrentUser().getId(), NetworkUtil.getIpAddress(request), tuple3));
    }

    @PostMapping("/cancel-handle-batch")
    @RequiresPermissions("illegal-monitoring:mo-filing-supervise:edit")
    public Result<Boolean> dealCancelBatch(@RequestBody List<MoFilingSuperviseVo> voList) {
        return success(service.updateDealCancelBatch(voList));
    }

    @PostMapping("/filing-batch")
    @RequiresPermissions("illegal-monitoring:mo-filing-supervise:edit")
    public Result<Boolean> filingBatch(@RequestBody List<MoFilingSuperviseVo> voList) {
        return success(service.updateFilingBatch(voList));
    }

}

